package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.VarietyType;
import com.fantastic.service.zjs.VarietyTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/5/30 09:31
 * @description: 菜品类型表后台控制器
 */
@RestController
@RequestMapping("/varietyType")
public class VarietyTypeControllerAdmin {

    @Resource
    private VarietyTypeService varietyTypeService;

    /**
     * 查询菜品类型信息
     * 使用分页插件后，Dao层和service层返回都要用Page替换原来的list集合
     * 无条件时是查询全部的分页查询
     * 有条件时是查询条件的分页查询
     *
     * @param varietyType
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listVarietyType")
    public ResultData listVarietyType(VarietyType varietyType,
                                      @RequestParam(name="page",
                                              defaultValue = "1") int pageNum,
                                      @RequestParam(name="limit",defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<VarietyType> varietyTypes = varietyTypeService.listVarietyType(varietyType);
        PageInfo<VarietyType> pageInfo = new PageInfo<>(varietyTypes);
        return new ResultData(RespStatusInfo.OK, pageInfo);
    }

    /**
     * 查询单类型
     *
     * @param varietyTypeId
     * @return
     */
    @GetMapping("/getVarietyType")
    public ResultData getVarietyType(Integer varietyTypeId) {
        return new ResultData(RespStatusInfo.OK, varietyTypeService.getVarietyType(varietyTypeId));
    }

    /**
     * 添加菜品类型
     *
     * @param varietyType
     * @return
     */
    @PostMapping("/insertVarietyType")
    public ResultData insertVarietyType(MultipartFile picture,VarietyType varietyType) {
        return new ResultData(RespStatusInfo.OK, varietyTypeService.insertVarietyType(picture,varietyType));
    }

    /**
     * 修改菜品类型
     *
     * @param varietyType
     * @return
     */
    @PostMapping("/updateVarietyType")
    public ResultData updateVarietyType(MultipartFile picture, VarietyType varietyType) {
        return new ResultData(RespStatusInfo.OK, varietyTypeService.updateVarietyType(picture,varietyType));
    }

    /**
     * 删除菜品类型
     *
     * @param varietyTypeId
     * @return
     */
    @PostMapping("/deleteVarietyType")
    public ResultData deleteVarietyType(Integer varietyTypeId) {
        return new ResultData(RespStatusInfo.OK, varietyTypeService.deleteVarietyType(varietyTypeId));
    }


}
